<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('处方信息列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>创建时间：</label>
                            <input type="text" class="time-input" placeholder="请选择创建时间" id="startTime" name="startTime"
                                   autocomplete="off"/>
                            -
                            <input type="text" class="time-input" placeholder="请选择创建时间" id="endTime" name="endTime"
                                   autocomplete="off"/>
                        </li>
                        <li>
                            <label>状态：</label>
                            <select name="status" id="drugType">
                                <option value="">全部</option>
                                <option value="未完结">未完结</option>
                                <option value="已完结">已完结</option>
                            </select></li>
                        <li>
                            <label>姓名：</label>
                            <input type="text" id="name" name="name" search="search"/>
                        </li>
<!--                        <li>-->
<!--                            <label>性别：</label>-->
<!--                            <input type="text" id="sex" name="sex" search="search"/>-->
<!--                        </li>-->
<!--                        <li>-->
<!--                            <label>年龄：</label>-->
<!--                            <input type="text" id="age" name="age" search="search"/>-->
<!--                        </li>-->
                        <li>
                            <label>身份证号：</label>
                            <input type="text" name="idNumber" search="search"/>
                        </li>
                        <li>
                            <label>医生：</label>
                            <select name="doctorid" id="doctorid" th:with="users=${@sysuser.getUsers(110)}">
                                <option value="">全部</option>
                                <option th:each="user : ${users}" th:text="${user.userName}"
                                        th:value="${user.userId}"></option>
                            </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                        <li><a class="btn btn-warning btn-rounded btn-sm" onclick="$.table.exportExcel()"
                               shiro:hasPermission="system:dict:export">
                            <i class="fa fa-download"></i> 导出
                        </a></li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.addFull('0')" shiro:hasPermission="system:records:add">
                <i class="fa fa-plus"></i> 新建处方
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:src="@{/js/common.js}"></script>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:records:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:records:remove')}]];
    var detailFlag = [[${@permission.hasPermi('system:records:detail')}]];
    var sexDic = [[${@dict.getType('sys_user_sex')}]];
    var prefix = ctx + "system/records";
    var statusDic = [{"dictLabel": "未完成", "dictValue": "0"},
        {"dictLabel": "未完成", "dictValue": "1"},
        {"dictLabel": "未完成", "dictValue": "2"},
        {"dictLabel": "已完成", "dictValue": "3"},]

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add/{id}",
            updateUrl: prefix + "/add/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            detailUrl: prefix + "/detail/{id}",
            modalName: "处方信息",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '自增ID',
                    visible: false
                },
                {
                    field: 'name',
                    title: '姓名'
                },
                {
                    field: 'sex',
                    title: '性别',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(sexDic, value);
                    }
                },
                {
                    field: 'age',
                    title: '年龄'
                },
                {
                    field: 'skinTest',
                    title: '皮试结果'
                },
                // {
                //     field: 'status',
                //     title: '状态',
                //     formatter: function (value, row, index) {
                //         return $.table.selectDictLabel(statusDic, value);
                //     }
                // },
                {
                    field: 'crtime',
                    title: '创建时间',
                    sortable: true,
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        let click_info = ""
                        // 已完成的处方和没皮试的处方不能编辑
                        if (row.status != 0) {
                            click_info = "disabled";
                        } else {
                            click_info = `onclick="$.operate.editFull(${row.id})"`
                        }
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" ' + click_info + '><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-info btn-xs ' + detailFlag + '" href="javascript:void(0)" onclick="$.operate.detailFull(\'' + row.id + '\')"><i class="fa"></i>详情</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function mysearch() {
        $.table.search()
    }
</script>
</body>
</html>